package com.itlong.cloud.sdk.resource;

import com.alibaba.fastjson.JSONObject;
import com.itlong.cloud.POJO.VO.sdk.old.SDKAppOldUserBasicsInfoVO;
import com.itlong.cloud.POJO.VO.sdk.old.SDKAppOldUserInfoCacheVO;
import com.itlong.cloud.app.service.IAppOldRegisterService;
import com.itlong.cloud.sdk.service.ISDKAppOldUserService;
import com.itlong.cloud.user.sdk.ISDKAppOldUserServiceClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* <desc>
*     APP SDK人员信息业务处理暴露接口实现类.
* </desc>
*
* @createDate 2017-11-08
*/
@RestController
public class SDKAppOldUserServiceResource implements ISDKAppOldUserServiceClient {


    @Autowired
    ISDKAppOldUserService iSDKAppOldUserService;

    @Autowired
    IAppOldRegisterService iAppOldRegisterService;

    /**
     * <desc>
     * 从缓存中获取SDK登录用户的信息.
     * </desc>
     *
     * @param appid   应用接入凭证
     * @param phoneNo 用户手机号
     * @return 手机APP SDK用户数据传输对象
     * @author LewisLouis
     * @createDate 2017-11-08
     */

    @Override
    @RequestMapping(path = "sdk/appUser/getSDKAppCacheUser",method = {RequestMethod.POST})
    public SDKAppOldUserInfoCacheVO getSDKAppCacheUser(@RequestParam("appid")String appid, @RequestParam("phoneNo")String phoneNo) {
        return iSDKAppOldUserService.getSDKAppCacheUser(appid,phoneNo);
    }

    /**
     * <desc>
     * 保存SDK登录的用户信息到缓存.
     * </desc>
     *
     * @param sdkAppUserVO 手机APP SDK用户数据传输对象
     * @author LewisLouis
     * @createDate 2017-11-08
     */

    @Override
    @RequestMapping(path = "sdk/appUser/saveSDKAppCacheUser",method = {RequestMethod.POST})
    public void saveSDKAppCacheUser(@RequestBody SDKAppOldUserInfoCacheVO sdkAppUserVO) {
        iSDKAppOldUserService.saveSDKAppCacheUser(sdkAppUserVO);
    }

    /**
     * <desc>
     * 从数据库中获取SDK登录用户的基础信息.
     * </desc>
     *
     * @param phoneNo 用户手机号
     * @return 手机APP SDK用户数据传输对象
     * @author LewisLouis
     * @createDate 2017-11-13
     */
    @Override
    @RequestMapping(path = "sdk/appUser/getSDKAppUserBasicInfo",method = {RequestMethod.POST})
    public SDKAppOldUserBasicsInfoVO getSDKAppUserBasicInfo(@RequestParam("phoneNo")String phoneNo) {
        return iSDKAppOldUserService.getSDKAppUserBasicInfo(phoneNo);
    }

    /**
     * <desc>
     * 根据手机号和应用接入凭证，查找对应的项目信息.
     * </desc>
     *
     * @param phoneNo 手机号
     * @param appId   应用接入凭证
     * @return 用户的项目相关信息（包括项目相关配置\住址列表等）
     * @author LewisLouis
     * @createDate 2017-11-14
     */
    @Override
    @RequestMapping(path = "sdk/appUser/getProjectInfos",method = {RequestMethod.POST})
    public List<String> getProjectInfos(@RequestParam("phoneNo")String phoneNo, @RequestParam("appId")String appId) {
        return iSDKAppOldUserService.getProjectInfos(phoneNo,appId);
    }

    /**
     * <desc>
     * 根据用户Id和项目Id，查找对应的项目信息.
     * </desc>
     *
     * @param userId    用户Id
     * @param projectId 项目编号
     * @return 用户的项目相关信息（包括项目相关配置\住址列表等）
     * @author LewisLouis
     * @createDate 2017-11-14
     */
    @Override
    @RequestMapping(path = "sdk/appUser/getUserProjectInfo",method = {RequestMethod.POST})
    public JSONObject getUserProjectInfo(@RequestParam("userId")String userId, @RequestParam("projectId")String projectId) {
        return iAppOldRegisterService.getUserProjectInfo(userId,projectId);
    }

    /**
     * <desc>
     * 获取指定用户的所在房间的其中一个业主的电话号码
     * </desc>
     *
     * @param userId
     * @return 业主电话号码
     * @author LewisLouis
     * @createDate 2017-11-15
     */
    @Override
    @RequestMapping(path = "sdk/appUser/getOneParentPhoneNoByUserId",method = {RequestMethod.POST})
    public String getOneParentPhoneNoByUserId(@RequestParam("userId")String userId) {
        return iSDKAppOldUserService.getOneParentPhoneNoByUserId(userId);
    }

    /**
     * <desc>
     * 获取用户指定项目中的一卡通软卡号（系统编号）
     * </desc>
     *
     * @param userId    用户Id
     * @param projectId 项目Id
     * @return 一卡通软卡号（系统编号）.
     * @author LewisLouis
     * @createDate 2017-11-16
     */
    @Override
    @RequestMapping(path = "sdk/appUser/getUserCardNo",method = {RequestMethod.POST})
    public String getUserCardNo(@RequestParam("userId")String userId, @RequestParam("projectId")String projectId) {
        return iSDKAppOldUserService.getUserCardNo(userId,projectId);
    }


}
